-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[AutoDiff] Support differentiation of branching cast instructions. #32069
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[AutoDiff] Support differentiation of branching cast instructions. #32069
Conversation
Add a common helper function `VJPEmitter::createTrampolineBasicBlock`. Change `VJPEmitter::buildPullbackValueStructValue` to take an original basic block instead of a terminator instruction.
This test was disabled in SR-12741 due to iphonesimulator-i386 failures. Enabling the test on other platforms is important to prevent regressions.
Support differentiation of `is` and `as?` operators. These operators lower to branching cast SIL instructions, requiring control flow differentiation support. Resolves SR-12898.
getOpASTType(ccabi->getTargetFormalType()), | ||
createTrampolineBasicBlock(ccabi, pbStructVal, ccabi->getSuccessBB()), | ||
createTrampolineBasicBlock(ccabi, pbStructVal, ccabi->getFailureBB()), | ||
ccabi->getTrueBBCount(), ccabi->getFalseBBCount()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: these newly added VJPEmitter
visitors significantly duplicate code from SILCloner
.
We can potentially just inherit SILCloner
visitors by baking createTrampolineBasicBlock
logic into VJPEmitter::remapBasicBlock
. This changes the meaning of VJPEmitter::getOpBasicBlock
used by other visitors though, so I'm not sure it would work.
// CHECK-LABEL: sil hidden [ossa] @${{.*}}checked_cast_addr_nonactive_result{{.*}} : $@convention(thin) <T where T : Differentiable> (@in_guaranteed T) -> @out T { | ||
// CHECK: checked_cast_addr_br take_always T in %3 : $*T to Float in %5 : $*Float, bb1, bb2 | ||
// CHECK: } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: I didn't add a test for checked_cast_value_br
because I'm not sure what Swift codes lowers to it. The as?
operators I tried all lowered to checked_cast_addr_br
.
The added control flow differentiation support is generic so I'm pretty sure checked_cast_value_br
differentiation works. We can add a test if we encounter a case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. Thanks!
@swift-ci Please smoke test |
@swift-ci Please smoke test Linux |
Support differentiation of
is
andas?
operators.These operators lower to branching cast SIL instructions, requiring control flow differentiation support:
checked_cast_br
checked_cast_value_br
checked_cast_addr_br
Resolves SR-12898.
Examples: